package com.kingdee.pda.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.basecommon.utils.PreferencesUtils;

import com.kingdee.pda.R;
import com.kingdee.pda.entity.ServerBean;

import java.util.List;

/**
 * @author：dlj
 * @data：2021/7/16:15:10
 * @des：
 */
public class ServerListAdapter extends BaseQuickAdapter<ServerBean, BaseViewHolder> {

    private Context context;

    public ServerListAdapter(Context context, List<ServerBean> beans) {
        super(R.layout.layout_server_list_item, beans);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder viewHolder, ServerBean item) {
        String content = TextUtils.isEmpty(item.getUrl()) ? item.getTitle() : item.getTitle() + "\n" + item.getUrl();
        viewHolder.setText(R.id.tv_content, content)
                .addOnClickListener(R.id.item)
                .addOnClickListener(R.id.tv_edit)
                .addOnLongClickListener(R.id.item);

        if (PreferencesUtils.getServerCount(context) == viewHolder.getLayoutPosition()) {
            viewHolder.setChecked(R.id.checkBox, true);
        } else {
            viewHolder.setChecked(R.id.checkBox, false);
        }

        if (mData.size() - 1 == viewHolder.getLayoutPosition()) {
            viewHolder.setVisible(R.id.tv_edit,false);
        }
    }
}
